{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "7fe823e9-146f-40ae-b7e0-552c228182e8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.865\n"
     ]
    }
   ],
   "source": [
    "#AdaBoost\n",
    "import pandas as pd\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn.ensemble import AdaBoostClassifier\n",
    "from sklearn.metrics import accuracy_score\n",
    "\n",
    "df = pd.read_excel('信用卡精准营销模型.xlsx')\n",
    "df.head()\n",
    "\n",
    "X = df.drop(columns='响应')\n",
    "y = df['响应']\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)\n",
    "\n",
    "clf = AdaBoostClassifier(random_state=123)\n",
    "clf.fit(X_train, y_train)\n",
    "y_pred = clf.predict(X_test)\n",
    "\n",
    "score = accuracy_score(y_pred, y_test)\n",
    "print(score)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a253919d-f61f-484e-b79b-fbd9f4bebcc2",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred_proba = clf.predict_proba(X_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "40d510b1-d3b2-4764-807b-a08415ab887a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAiMAAAGdCAYAAADAAnMpAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjEsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvc2/+5QAAAAlwSFlzAAAPYQAAD2EBqD+naQAAJt9JREFUeJzt3QtcVWW+//Efd0QBRRQEUdQyNS8oCKE5HTsWk75snJlew1FT84I1XV6NnumillZWNp4ym6IYL4zdTKtT/Wt0cIr01TFJCrKs1MJL4AWQlIso173+r+cpGFFQUDYPe+/P+/VasddiLfaPR2J9Wet5nuVmWZYlAAAAhribemMAAACFMAIAAI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LlzYRlW7hvwmzoXq6b5nzpzR/XVam9NeGYFjeOqpp3THynfffVd3YEPrUY/tnjZtmu4wHBwcbLocp2az2fTVp1WrVkl0dLQkJibKokWLJCUlxXRpTkV1qlRXnF588UXJzs6Wd955RzZt2iRLly41XRouk9NeGVG/fD08PKSgoKDBdrUeGhra6DFqe0v2x6W1c52nn35ah5GPPvpIhg4daudKXa+t9+/fL4cOHdK96M8+aSqenp6yb98+6devXxtU7vw/02oEjZeXlz6uzsCBA/VfmOp2hLe3t93rdoV2fvjhh3XAnjNnjl5XIx7Ly8tl7ty5Ovyp2zy4fE2dCwMCAuxyVURx2n859T+/+gslPT29wS9ita7u7TZGbT97f+XDDz9scn9cWjsry5cv13/NpKWlSUxMTBtV61ptrYao7969W9+iqVtuvvlmGTt2rH6thkWidX6mR48erW/N1IU95fvvv9chhSDSeu2s+pedGzjqAiCPWWs9Rs6FlpMPG1PDwNatW6eHJ82dO1cPG8vPz9efnzZtmvXggw82GNrr6elpPf3003rI6ZIlSxjaa4d2fuqpp/Rwvrfffts6duxY/VJWVmbwu3DOtj4Xo2ns0865ubl6RNjdd99t7du3z/rHP/5hde/e3Xr88ccNfhfO187qd7Jq5zfeeEMPP/3Xv/5l9evXT4+ERNPU71Y1lYJa1Gl/xYoV+vWPP/6oP6/aWLX1uUN777vvPn0uVFMxMLT3Mqnx0b169dInPzWM7LPPPqv/3HXXXad/OZ/tzTfftPr376/3V0ObNm3aZKBq527n3r176/8hzl3ULxq0/s/02Qgj9mvnHTt26KkA1MlVDfN94okn9LBqtF47V1dXW4888ogOIL6+vlZERIR15513WidPnjRUvWPYunVro79z69pWfVRtfe4xUVFR+t9F/Tz//e9/t2uNbuo/9rvuAgAA4KJ9RgAAgGMgjAAAAKMIIwAAwCjCCAAAMIowAgAAjCKMAAAAowgjAADAKMIIAAAwijACAACMIowAAACjCCMAAMAowggAABCT/j/ODHcK3riekgAAAABJRU5ErkJggg==",
      "text/plain": [
       "<Figure size 640x480 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.metrics import roc_curve\n",
    "fpr, tpr, thres = roc_curve(y_test.values, y_pred_proba[:,1])\n",
    "import matplotlib.pyplot as plt\n",
    "plt.plot(fpr, tpr)\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5aa9d524-0dc5-4952-825e-74f3c61423a4",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba0fbd73-63b9-4508-a963-d10f4b30a983",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0bbf279c-cbfb-45be-85ab-8a673c365675",
   "metadata": {},
   "outputs": [],
   "source": [
    "#GBDT模型\n",
    "import pandas as pd\n",
    "from sklearn.preprocessing import LabelEncoder #贴标签\n",
    "\n",
    "df = pd.read_excel('产品定价模型.xlsx')\n",
    "le = LabelEncoder()\n",
    "df['类别'] = le.fit_transform(df['类别'])\n",
    "le = LabelEncoder()\n",
    "df['纸张'] = le.fit_transform(df['纸张'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "9981c979-f122-4b2f-af0e-11dfb614b563",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>页数</th>\n",
       "      <th>类别</th>\n",
       "      <th>彩印</th>\n",
       "      <th>纸张</th>\n",
       "      <th>价格</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>207</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>210</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>206</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>62</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>218</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>64</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>209</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>60</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    页数  类别  彩印  纸张  价格\n",
       "0  207   1   0   1  60\n",
       "1  210   1   0   1  62\n",
       "2  206   1   0   1  62\n",
       "3  218   1   0   1  64\n",
       "4  209   1   0   1  60"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7fabe4ea-6852-4cb9-82ce-8afd3ce4a4d6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.8741691363311168"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from sklearn.ensemble import GradientBoostingRegressor\n",
    "X = df.drop(columns='价格')\n",
    "y = df['价格']\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=123)\n",
    "model = GradientBoostingRegressor(random_state=123)\n",
    "model.fit(X_train, y_train)\n",
    "y_pred = model.predict(X_test)\n",
    "model.score(X_test, y_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b16a9fec-1271-42e5-b46c-e1ebbd6da916",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
